﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKRevitBase.WinForm;

namespace YJKDataLookAfter
{
	[Regeneration(RegenerationOption.Manual)]
	[Transaction(TransactionMode.Manual)]
	internal class CmdProjectManager : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
		{
			try
			{
				Process[] processesByName = Process.GetProcessesByName("Revit");
				if (processesByName.Length != 0)
				{
                    WindowHandle owner = new WindowHandle(processesByName[0].MainWindowHandle);
					if (XmlUtils.GetDataFromConfigFile(AssistFunc.GetAppRootPath() + "\\Data\\Config.xml", "Server", "value") == "")
					{
						MessageBox.Show("请先运行‘服务器连接配置’命令配置服务器。");
					}
					else
					{
						DlgPM.GetInstance().ShowDialog(owner);
					}
				}
			}
			catch
			{
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
